home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-18 | 2.3 KB | 100 lines | [TEXT/MPS ] |
- #include <files.h>
- #include <resources.h>
- #include <folders.h>
- #include <errors.h>
- #include <icons.h>
- #include <toolutils.h>
-
- #include "inttypes.h"
- #include "specs.h"
- #include "getfoldername.h"
- #include "makestartupfolder.h"
-
- #define rootDirID 2
- #define iconresid -16455
-
- #define diskiconresource 200
-
- #define thestringlist 200
- #define iconfilestring 1
-
- extern OSErr installfoldericons( int16 resid, const FSSpec& folder );
-
- OSErr makestartupfolder( const FSSpec& volume )
- {
- Str255 name;
- OSErr error = getfoldername( kStartupFolderType, name );
- if ( error != noErr )
- return error;
-
- FSSpec folder;
- error = childfsspec( volume, name, folder );
- if ( error != noErr && error != fnfErr )
- return error;
-
- if ( error == fnfErr )
- {
- int32 dirid;
- error = FSpDirCreate( &folder, 0, &dirid );
- }
-
- (void)installfoldericons( startupFolderIconResource, folder );
- (void)installfoldericons( diskiconresource, volume );
- return noErr;
- }
-
- OSErr installfoldericons( int16 resid, const FSSpec& folder )
- {
- FSSpec iconfile;
- Str255 iconfilename;
- GetIndString( iconfilename, thestringlist, iconfilestring );
- OSErr error = childfsspec( folder, iconfilename, iconfile );
- if ( error == noErr )
- return dupFNErr;
- if ( error != fnfErr )
- return error;
-
- FSpCreateResFile( &iconfile, 0, 0, 0 );
- if ( ResError() != noErr )
- return ResError();
-
- int16 iconref= FSpOpenResFile( &iconfile, fsRdWrPerm );
- if ( ResError() != noErr )
- return ResError();
-
- static OSType types[]= { 'icl4', 'icl8', 'ICN#', 'ics#', 'ics4', 'ics8', 0 };
- for ( uint16 i=0; types[i]!=0; i++ )
- {
- Handle res= GetResource( types[i], resid );
- if ( res == 0 )
- continue;
-
- DetachResource( res );
- AddResource( res, types[i], iconresid, "\p" );
- WriteResource( res );
- }
-
- CloseResFile( iconref );
-
- FInfo info;
- if ( FSpGetFInfo( &iconfile, &info ) == noErr )
- {
- info.fdFlags |= fInvisible;
- info.fdFlags &= ~0x0100;
- (void)FSpSetFInfo( &iconfile, &info );
- }
-
- CInfoPBRec pb;
- pb.dirInfo.ioCompletion=0;
- pb.dirInfo.ioNamePtr= (StringPtr)&folder.name;
- pb.dirInfo.ioVRefNum= folder.vRefNum;
- pb.dirInfo.ioFDirIndex= 0;
- pb.dirInfo.ioDrDirID= folder.parID;
- if ( PBGetCatInfoSync( &pb ) == noErr )
- {
- pb.dirInfo.ioDrDirID= folder.parID;
- pb.dirInfo.ioDrUsrWds.frFlags = 0x400;
- (void)PBSetCatInfoSync( &pb );
- }
- }
-